{% extends "profile/base.html" %}

{% block title %}文件列表 - 用户资料管理系统{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <!-- 页面标题 -->
            <div class="text-center mb-4 fade-in">
                <h1 class="fw-bold text-primary">
                    <i class="fas fa-folder-open me-2"></i>我的文件
                </h1>
                <p class="text-muted">管理您上传的所有文件</p>
            </div>

            <!-- 文件列表卡片 -->
            <div class="card shadow-sm fade-in">
                <div class="card-header bg-gradient text-white">
                    <div class="d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">
                            <i class="fas fa-list me-2"></i>文件列表
                        </h5>
                        <a href="{{ url_for('profile.upload_file') }}" class="btn btn-light btn-sm">
                            <i class="fas fa-plus me-1"></i>上传新文件
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    {% if files.items %}
                    <div class="table-responsive">
                        <table class="table table-hover" id="files-table">
                            <thead class="table-light">
                                <tr>
                                    <th><i class="fas fa-file me-1"></i>文件名</th>
                                    <th><i class="fas fa-tag me-1"></i>类型</th>
                                    <th><i class="fas fa-weight me-1"></i>大小</th>
                                    <th><i class="fas fa-calendar me-1"></i>上传时间</th>
                                    <th><i class="fas fa-eye me-1"></i>状态</th>
                                    <th><i class="fas fa-cogs me-1"></i>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for file in files.items %}
                                <tr id="file-{{ file.id }}">
                                    <td>
                                        <div class="d-flex align-items-center">
                                            <i class="fas fa-file me-2 text-muted"></i>
                                            <div>
                                                <div class="fw-medium">{{ file.original_filename }}</div>
                                                {% if file.description %}
                                                <small class="text-muted">{{ file.description }}</small>
                                                {% endif %}
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        {% if file.category == 'image' %}
                                        <span class="badge bg-primary">图片</span>
                                        {% elif file.category == 'document' %}
                                        <span class="badge bg-success">文档</span>
                                        {% elif file.category == 'video' %}
                                        <span class="badge bg-danger">视频</span>
                                        {% elif file.category == 'audio' %}
                                        <span class="badge bg-info">音频</span>
                                        {% else %}
                                        <span class="badge bg-secondary">其他</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ (file.file_size / 1024)|round(2) }} KB</td>
                                    <td>{{ file.upload_time.strftime('%Y-%m-%d %H:%M') }}</td>
                                    <td>
                                        {% if file.is_public %}
                                        <span class="badge bg-success">公开</span>
                                        {% else %}
                                        <span class="badge bg-warning">私有</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <div class="btn-group" role="group">
                                            <a href="{{ url_for('profile.download_file', file_id=file.id) }}" 
                                               class="btn btn-sm btn-outline-primary" title="下载">
                                                <i class="fas fa-download"></i>
                                            </a>
                                            <button type="button" class="btn btn-sm btn-outline-danger" 
                                                    onclick="deleteFile({{ file.id }})" title="删除">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- 分页 -->
                    {% if files.pages > 1 %}
                    <nav aria-label="文件列表分页">
                        <ul class="pagination justify-content-center">
                            {% if files.has_prev %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('profile.file_list', page=files.prev_num) }}">
                                    <i class="fas fa-chevron-left"></i>
                                </a>
                            </li>
                            {% endif %}
                            
                            {% for page_num in files.iter_pages() %}
                                {% if page_num %}
                                    {% if page_num != files.page %}
                                    <li class="page-item">
                                        <a class="page-link" href="{{ url_for('profile.file_list', page=page_num) }}">{{ page_num }}</a>
                                    </li>
                                    {% else %}
                                    <li class="page-item active">
                                        <span class="page-link">{{ page_num }}</span>
                                    </li>
                                    {% endif %}
                                {% else %}
                                <li class="page-item disabled">
                                    <span class="page-link">...</span>
                                </li>
                                {% endif %}
                            {% endfor %}
                            
                            {% if files.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('profile.file_list', page=files.next_num) }}">
                                    <i class="fas fa-chevron-right"></i>
                                </a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                    {% endif %}
                    {% else %}
                    <div class="text-center py-5">
                        <i class="fas fa-folder-open fa-4x text-muted mb-3"></i>
                        <h5 class="text-muted">暂无文件</h5>
                        <p class="text-muted">您还没有上传任何文件</p>
                        <a href="{{ url_for('profile.upload_file') }}" class="btn btn-primary">
                            <i class="fas fa-upload me-2"></i>上传第一个文件
                        </a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<style>
    .bg-gradient {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    
    .fade-in {
        opacity: 0;
        animation: fadeIn 0.5s ease-in forwards;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(20px); }
        to { opacity: 1; transform: translateY(0); }
    }
    
    .table-hover tbody tr:hover {
        background-color: rgba(67, 97, 238, 0.05);
    }
    
    .btn-group .btn {
        transition: all 0.2s;
    }
    
    .btn-group .btn:hover {
        transform: translateY(-2px);
    }
    
    .pagination .page-link {
        color: #667eea;
    }
    
    .pagination .page-item.active .page-link {
        background-color: #667eea;
        border-color: #667eea;
    }
</style>
{% endblock %}

{% block extra_js %}
<script>
    $(document).ready(function() {
        // 初始化动画
        $('.fade-in').each(function(index) {
            $(this).delay(100 * index).animate({ opacity: 1 }, 500);
        });
    });
</script>
{% endblock %}